package com.le.tester.book.effectivejava3rdchinese.secondReading.l02;

import java.util.EnumSet;
import java.util.Set;

/**
 * createTime：2024-08-02 13:48
 * description：使用Builder搭建类的层次结构，抽象的pizza，参数够多的时候建议使用Builder模式来初始化参数
 * 也可以都提供，到时候就可以进行选择
 */
public abstract class Pizza {

    public enum Topping {HAM, MUSHROOM, ONION, PEPPER, SAUSAGE}

    final Set<Topping> toppings;

    abstract static class Builder<T extends Builder<T>> {

        EnumSet<Topping> toppings = EnumSet.noneOf(Topping.class);

        public T addTopping(Topping topping) {
            toppings.add(topping);
            return self();
        }

        abstract Pizza build();

        protected abstract T self();
    }

    Pizza(Builder<?> builder) {
        toppings = builder.toppings.clone();
    }


}
